package reflect;

import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.URISyntaxException;
import java.util.Arrays;

public class Text2 {
    public static void main(String[] args) throws Exception {
        File dir = new File(
                Text2.class.getResource(".").toURI()
        );
        File[] files = dir.listFiles(f->f.getName().endsWith(".class"));
        for (int i = 0; i <files.length ; i++) {
            String s = files[i].getName();
            s = s.substring(0,s.lastIndexOf("."));
            Class cls = Class.forName(Text2.class.getPackage().getName()+"."+s);
            Object obj = cls.newInstance();
            getMethod(obj,cls);
        }
    }

    public static void getMethod(Object obj,Class cls) throws InvocationTargetException, IllegalAccessException {
        Method[] methods = cls.getDeclaredMethods();
        for (Method method : methods) {
            if (method.getParameterCount() == 0 &&
                    method.getModifiers() == Modifier.PUBLIC) {
                method.invoke(obj);
            }
        }
    }
}
